package com.jd.xsl.reader;

import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Workbook;

import com.jd.xsl.field.DataSheet;
import com.jd.xsl.field.Sheet;
import com.jd.xsl.parserule.ParseRule;
import com.jd.xsl.parserule.PortraitRule;
import com.jd.xsl.util.ExcelUtil;

public class XSLReader {
	public static DataSheet importExcel(List<Sheet> sheets,ParseRule rule, String file) {
		DataSheet results = new DataSheet();
		Workbook book = null;

		try {
			book = ExcelUtil.getWorkbook(file);
		} catch (Exception e) {
			 e.printStackTrace();
		}

		for (Sheet sheet : sheets){
			List<Map<String, Object>> dataset = null;
			if (rule instanceof PortraitRule){
				PortraitReader reader = new PortraitReader();
				dataset = reader.read((PortraitRule)rule, book.getSheet(sheet.getName()));
			}
			results.put(sheet.getName(), dataset);

		}
		return results;
		
	}
}
